const Router = require("koa-router");
const pool = require('../database.js');
const {getList,postData,putData,deleteData,anthVertify,getListAll} =require('../common/middleware.js')
const router = new Router({
  prefix: "/project",
});
router.get("/",anthVertify, async(ctx, next) => {
    await getList(ctx,{table:'project',otherState:`WHERE userId=${ctx.user.id}`})
});
router.post("/", anthVertify,async(ctx, next) => {
   await postData({table:'project',data:{...ctx.request.body,userId:ctx.user.id},ctx:ctx})
});
router.put("/", async(ctx, next) => {
   await putData('project',ctx.request.body,ctx)
  });
  router.delete("/:id", async(ctx, next) => {
    let id=ctx.params.id
   await deleteData('project',id,ctx)
  });
  router.get("/getAlled",anthVertify, async(ctx, next) => {
    let result= await getListAll(ctx,{table:'project',queryData:'id,ename',otherState:`WHERE userId=${ctx.user.id}`})
    ctx.body = result
 });
module.exports = router;
